//
//  DDropDurationLayer.swift
//  Drop
//
//  Created by hushaohua on 2018/9/23.
//  Copyright © 2018年 init. All rights reserved.
//

import UIKit

class DDropDurationLayer: CALayer {
    var attributes:[NSAttributedStringKey : Any] = [:];
    var string:NSString = "";

    override func draw(in ctx: CGContext) {
        let size = string.size(withAttributes: self.attributes);
        let offsetX = (self.bounds.size.width - size.width) / 2;
        let offsetY = (self.bounds.size.height - size.height) / 2;
        
        
        ctx.setLineWidth(1/UIScreen.main.scale);
        ctx.setStrokeColor(UIColor.lightGray.cgColor);
        ctx.setLineDash(phase: 0, lengths: [2,2]);
        ctx.move(to: CGPoint(x:0,y:self.bounds.size.height / 2));
        ctx.addLine(to: CGPoint(x:offsetX, y:self.bounds.size.height / 2));
        ctx.closePath();
        ctx.strokePath();
        
        ctx.move(to: CGPoint(x:offsetX + size.width,y:self.bounds.size.height / 2));
        ctx.addLine(to: CGPoint(x:self.bounds.size.width, y:self.bounds.size.height / 2));
        ctx.closePath();
        ctx.strokePath();
        
        string.draw(at: CGPoint(x: offsetX, y: offsetY), withAttributes: self.attributes);
    }
}
